package com.zhang.logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/29 21:21
 */
@RestController
@Slf4j
public class LoggerController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/test1")
    public String test1(){
        System.out.println("success");
        return "success";
    }

    @RequestMapping("/test2")
    public String test2(@RequestParam("name") String name,@RequestParam(value = "age",defaultValue = "18") int age){
        System.out.println(name+":"+age);
        return "success";
    }

    @RequestMapping("/applog")
    public String getLogger(@RequestParam("param") String jsonStr){

        //System.out.println(jsonStr);
        //将日志落盘
        log.info(jsonStr);
        //将日志发到kafka
        kafkaTemplate.send("ods_base_log",jsonStr);
        return "success";
    }

}
